package com.feilx.changggou.seckill.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;


import com.changgou.bean.PageVo;
import com.changgou.bean.QueryCondition;
import com.changgou.bean.Resp;
import com.changgou.utils.DateUtil;
import com.changgou.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.feilx.changggou.seckill.entity.TbSeckillEntity;
import com.feilx.changggou.seckill.service.TbSeckillService;




/**
 *
 *
 * @author feilx
 * @email 852371260@qq.com
 * @date 2020-08-13 22:05:44
 */
@Api(tags = " 管理")
@RestController
@RequestMapping("order/tbseckill")
public class TbSeckillController {
    @Autowired
    private TbSeckillService tbSeckillService;



    @ApiOperation("获取时间菜单")
    @GetMapping("/menus")
    public Resp<List<Date>> queryMenus(){
        List<Date> dateMenus = DateUtil.getDateMenus();
        return Resp.ok(dateMenus);
    }


    @ApiOperation("获取秒杀商品")
    @GetMapping("/list")
    public  Resp<List<TbSeckillEntity>> querySeckillGoods(@RequestParam("time")String time){
        return Resp.ok(tbSeckillService.querySecillGoods(time));
    }

    @ApiOperation("查看秒杀商品")
    public Resp<TbSeckillEntity>  getSeckillGood(@RequestParam("time") String time,
                                                 @RequestParam("id")Long id){
        TbSeckillEntity good =   tbSeckillService.getSecillGood(time,String.valueOf(id));
        return Resp.ok(good);
    }

    /**
     * 列表
     */
    @ApiOperation("分页查询(排序)")
    @GetMapping("/list")
    public Resp<PageVo> list(QueryCondition queryCondition) {
        PageVo page = tbSeckillService.queryPage(queryCondition);
        return Resp.ok(page);
    }


    /**
     * 信息
     */
    @ApiOperation("详情查询")
    @GetMapping("/info/{id}")
    public Resp<TbSeckillEntity> info(@PathVariable("id") Long id){
		TbSeckillEntity tbSeckill = tbSeckillService.getById(id);
        return Resp.ok(tbSeckill);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    public Resp<Object> save(@RequestBody TbSeckillEntity tbSeckill){
		tbSeckillService.save(tbSeckill);
        return Resp.ok(null);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    public Resp<Object> update(@RequestBody TbSeckillEntity tbSeckill){
		tbSeckillService.updateById(tbSeckill);
        return Resp.ok(null);
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    public Resp<Object> delete(@RequestBody Long[] ids){
		tbSeckillService.removeByIds(Arrays.asList(ids));
        return Resp.ok(null);
    }

}
